package com.atguigu.system.manager;

import com.atguigu.model.system.SysUser;
import com.atguigu.model.vo.user.SysUserQueryReqVo;
import com.atguigu.model.vo.user.SysUserQueryRespVo;
import com.atguigu.system.mapper.SysUserMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author flyduck
 * @since 2023-10-25
 */
@Component
public class SysUserManager extends ServiceImpl<SysUserMapper, SysUser>{

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 条件分页查询
     * @param pageParam
     * @param sysUserQueryReqVo
     * @return
     */
    public Page<SysUserQueryRespVo> selectPage(Page<SysUser> pageParam, SysUserQueryReqVo sysUserQueryReqVo) {
        return sysUserMapper.selectPage(pageParam,sysUserQueryReqVo);
    }

    /**
     * 根据username查询用户
     * @param username
     * @return
     */
    public SysUser findOneByUsername(String username) {
        QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username", username);
        return sysUserMapper.selectOne(queryWrapper);
    }
}
